// pages/student/homework/homeworkList/homework.js
var app = getApp();
import {student_active} from "../../../../asserts/js/common/barList";
import {post} from "../../../../asserts/js/request";
import {initCourseInit, getDanceKindParam} from "../../../../asserts/js/common/shareFun";
Page({

  /**
   * 页面的初始数据
   */
  data: {
    barList: student_active(1),
    top: app.globalData.bottom + 'px',
    homeworkList: [],
    tabObj: {
      tabList: [
        {},
        {
          name: "作业状态",
          code: "level",
          active: false,
          templete: "list-sort",
          cascadeObj: [
            {
              name: "全部",
              code: "",
              active: true
            },
            {
              name: "未完成",
              code: "0",
              active: false
            },
            {
              name: "已完成",
              code: "1",
              active: false
            }
          ]
        }
      ],
      activeIndex: 0
    },
    alter_show: false,
    buttom_title: {
      title1: '舞种',
      title2: "作业状态"
    },
    popconItem: '',
    tempList: Object,
    danceKind: [],
    isFinish: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getData();
    var obj = initCourseInit(app.globalData.enum_courseTypes, [], []);
    console.log(obj);
    this.setData({
      ["tabObj.tabList[0]"]: obj.tabList[0]
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  selectBoxShow: function(){
    this.setData({
      alter_show: true
    })
  },
  alterCancel: function() {
    this.setData({
      alter_show: false
    })
  },
  getData: function() {
    let this_ = this;
    post("stu-queryHomework",{
      studentId: app.globalData.studentInfo.studentId,
      danceKind: this_.data.danceKind.join("|"),
      isFinish: this_.data.isFinish.join("|")
    }).then(data => {
      console.log(data);
      var list = data.courseInfo.map(item => {
        var tagList = new Array();
        tagList.push({
          name: item.courseNature
        });
        tagList.push({
          name: item.courseKind
        });
        tagList.push({
          name: item.danceKind
        })
        item.assignTime = item.assignTime.split(" ")[0]
        item.tagList = tagList;
        return item;
      })
      this_.setData({
        homeworkList: list
      });
    }).catch(err => {
      console.log(err);
    })
  },
  itemClick: function(e) {
    this.setData({
      popconItem: {
        top: (e.detail.y - 67) + 'px',
        left: (e.detail.x - 100) + 'px',
        finish: e.currentTarget.dataset.item.isFinish,
        show: true,
      },
      tempList: e.target.dataset.item
    })
  },
  goCourse: function(e){
    wx.setStorageSync('courseItem', this.data.tempList);
    this.setData({
      ["popconItem.show"]: false
    })
    wx.navigateTo({
      url: '/pages/student/homework/courseDetail/courseDetail',
    })
  },
  selectSure: function(e) {

    var isFinish = []
    if(!e.detail.tabList[1].cascadeObj[0].active) {
      e.detail.tabList[1].cascadeObj.map(item => {
        if(item.active) {
          isFinish.push(item.code)
        }
      })
    }
    let this_ = this;
    this.setData({
      danceKind: getDanceKindParam(e.detail.tabList[0].cascadeObj),
      isFinish: isFinish
    }, function() {
      this_.getData()
      this_.setData({
        alter_show: false
      })
    })
  }
})